﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using PMQLCHH.DAO;
using PMQLCHH.DTO;


namespace PMQLCHH.BUS
{
    public class KhachHangBUS
    {
        #region Insert,Update,Delete
       
        public static bool InsertKhachHang(KhachHangDTO kh)
        {
            bool kq;
            kq = KhachHangDAO.InsertKhachHang(kh);
            return kq;
        }

        public static bool UpdateKhachHang(KhachHangDTO kh)
        {
            bool kq;
            kq = KhachHangDAO.UpdateKhachHang(kh);
            return kq;
        }

        public static bool DeleteKhachHang(KhachHangDTO kh)
        {
            bool kq;
            kq = KhachHangDAO.DeleteKhachHang(kh);
            return kq;
        }

        #endregion

        #region Select

        public static DataTable LoadListKhachHang()
        {
            DataTable dt = KhachHangDAO.LoadListKhachHang();
            return dt;
        }

        public static string GetMaKhachHang()
        {
            DataTable dt_kt = KhachHangDAO.LoadListKhachHang();
            string makh = "";
            if (dt_kt.Rows.Count > 0)
            {

                DataTable dt = KhachHangDAO.GetMaKhachHang();
                makh = "KH" + (int.Parse(dt.Rows[0]["MaKhachHang"].ToString().Substring(2)) + 1).ToString();
            }
            else
            {
                makh = "KH1000001";
            }
            return makh;
        }



        public static DataTable LoadListLoaiKhachHang()
        {
            DataTable dt = KhachHangDAO.LoadListLoaiKhachHang();
            return dt;
        }

        public static DataTable SearchKhachHang(KhachHangDTO kh,int flag)
        {
            DataTable dt = KhachHangDAO.SearchKhachHang(kh, flag);
            return dt;
            
        }
        //Kha Nguyen - ho tro cho Hoa Don - 12/6/2013 - begin
        /// <summary>
        /// Lay Thong Tin Khach Hang khi co ma khach hang
        /// </summary>
        ///
        public static KhachHangDTO LayThongTinKhachHang(string MaKH)
        {
            KhachHangDTO KH = new KhachHangDTO();
            DataTable dt = KhachHangDAO.LayThongTinKhachHang(MaKH);
            if (dt.Rows.Count != 0)
            {
                KH.Makhachhang = dt.Rows[0]["MaKhachHang"].ToString();
                KH.Tenkhachhang = dt.Rows[0]["TenKhachHang"].ToString();
                KH.Sodienthoai = dt.Rows[0]["SoDienThoai"].ToString();
                KH.Masothue = dt.Rows[0]["MaSoThue"].ToString();
                KH.Diachi = dt.Rows[0]["DiaChi"].ToString();
            }
            return KH;
        }
        //Kha Nguyen - ho tro cho Hoa Don - 12/6/2013 - end
        #endregion



    }
}
